package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import pojo.MenuItem;
import util.ConexaoPPCP;

public class MenuItemDao {
	private ArrayList<MenuItem> menuItem = new ArrayList<MenuItem>();

	public ArrayList<MenuItem> localizarMenuItem(int id_cat, int id_menu) throws SQLException, ClassNotFoundException {
		Connection conexao = ConexaoPPCP.getConexaoPPCP();
		String sql = "select distinct i.label,i.descricao, i.acao from menu m, menuitem i, categoriamenuitem c where m.id=i.menu_id and c.menuitem_id =i.id and c.categoriausuario_id=? and m.id=?";
		PreparedStatement pst = conexao.prepareStatement(sql);
		pst.setInt(1, id_cat);
		pst.setInt(2, id_menu);
		ResultSet rs = pst.executeQuery();
		//conexao.close();
		while(rs.next()){
			MenuItem meuMenuItem = new MenuItem();
			meuMenuItem.setLabel(rs.getString("label"));
			meuMenuItem.setDescricao(rs.getString("descricao"));
			meuMenuItem.setAcao(rs.getString("acao"));
			menuItem.add(meuMenuItem);
		}
		return menuItem;
	}
}
